﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using My_TV_Manager.Model;

namespace My_TV_Manager.View.ContentPanel.Track
{
    [System.ComponentModel.DesignerCategory("")]

    public class SearchResultPanel : SeriesDisplayPanel
    {
        #region Private Data

        private bool isTracked;

        #endregion

        #region Properties

        public bool IsTracked
        {
            get { return isTracked; }
            set { isTracked = value; }
        }

        #endregion

        #region Constructors

        // Declare the necessary constructor for the inherited class
        public SearchResultPanel(SearchResult searchResult, double bannerScale,
                                 Size size, Controller controller)
            : base(searchResult, bannerScale, size, controller) 
        {
            // Set the proper text for the button
            var trackedSeries = controller.TrackedSeries;

            manageButton.Text = "Add";
            isTracked = false;

            foreach (SearchResult series in trackedSeries)
            {
                if (series.SeriesName == searchResult.SeriesName)
                {
                    manageButton.Text = "Remove";
                    isTracked = true;
                    break;
                }
            }
        }

        #endregion

        #region Event Handlers

        // Handles the click on the manage button to add/remove a search result
        protected override void ManageClickHandler(object sender, EventArgs e)
        {
            if (isTracked) { controller.RemoveTrackedSeries(searchResult); }
            else { controller.AddTrackedSeries(searchResult); }
        }

        #endregion

        #region Functions

        public void UpdatePanel()
        {
            if (isTracked)
            {
                manageButton.Text = "Add";
                isTracked = false;

                return;
            }

            manageButton.Text = "Remove";
            isTracked = true;
        }

        #endregion
    }
}
